// 11-散列1 电话聊天狂人
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "../base/HashTable.c"

/* current =========================================*/
#define TelLength 12

typedef struct {
    char tel[TelLength];
    int count;
} Phone;

// HashTable 中用到的3个函数
int hash(void* tel) {
    return atoi(tel+3);
}

int sameKey(void* a, void* b) {
    return strcmp(a, b) == 0;
}

void destroyKeyAndValue(void* key, void* value) {
    free(value);
}

// 找到电话最多的人
void findMax(Phone** ps, int n) {
    Phone* max = ps[0];
    int same = 1;
    for (int i=1; i<n; i++) {
        Phone* p = ps[i];
        if (p->count > max->count) {
            max = p;
            same = 1;
        } else if (p->count == max->count) {
            if (strcmp(p->tel, max->tel) < 0) {
                max = p;
            }
            same++;
        }
    }
    if (same == 1) {
        printf("%s %d\n", max->tel, max->count);
    } else {
        printf("%s %d %d\n", max->tel, max->count, same);
    }
}

int main() {
    int n;
    scanf("%d", &n);
    HashTable *h = createHashTable(n*2, hash, sameKey, destroyKeyAndValue);
    for (int i=0; i<2*n; i++) {
        char tel[TelLength];
        scanf("%s", tel);
        Phone *p = find(h, tel);
        if (p == NULL) {
            p = (Phone *) malloc(sizeof(Phone));
            strcpy(p->tel, tel);
            p->count = 1;
            insert(h, p->tel, p);
        } else {
            p->count++;
        }
    }
    int len;
    Phone** ps = (Phone**) valueArray(h, &len);
    // for (int i=0; i<len; i++) {
    //     printf("%s %d\n", ps[i]->tel, ps[i]->count);
    // }
    findMax(ps, len);
    free(ps);
    destroyHashTable(h);
    return 0;
}
